<layout name="page" />
<block name="content">
	<select name="node_list" id="node_list" class="hidden">
		{:fill_option($node_list)}
	</select>
	{:widget('page_header/simple',array('name'=>'菜单管理'))}
	<div class="operate-panel">
		<form id="form_search" name="form_search" method="post" action="" style="display:flex;line-height: 36px;" >
			<select name="eq_pid" id="eq_pid" class="select w10">
				{:fill_option($top_node)}
			</select>
			<i class="icon"></i>
		</form>
		<i class="mid"></i>
		<a class="btn btn-normal" onclick="add()">新增</a>
		<a class="btn btn-normal" onclick="save()">保存</a>
		<i class="split"></i>
		<a class="btn btn-del" onclick="del()">删除</a>
	</div>
	<div class="x1 sub box">
		<div class="w28 m100 frame" style="max-height:520px;overflow-y: auto;">
			<div class="tree-menu" style="border-bottom: 1px solid #ccc;">
				<a node="{$eq_pid}" style="padding-left:8px;width:100%;display:block;line-height: 32px;">{$pid_name}</a>
				<php>
					if(!empty($tree_menu)){
				</php>
				<input type="hidden">
				<php>
					}
				</php>
			</div>
			<div class="tree-menu">
				{:widget('html/tree_menu',array($tree_menu))}
			</div>
		</div>
		<div style="width:16px;"></div>
		<div class="x1 frame m100" style="height:520px;">
			<form id="form_data" name="form_data" method="post" >
				<input type="hidden" name="id" id="id">
				<input type="hidden" name="ajax" id="ajax" value="1">
				<input type="hidden" name="opmode" id="opmode" value="">
				<div class="box">
					<label class="input-label" for="name">名称*：</label>
					<input class="input w19" type="text" id="name" name="name" check="required" info="请输入名称">
				</div>
				<div class="box">
					<label class="input-label" for="url">地址：</label>
					<input class="input w19" type="text" id="url" name="url">
				</div>
				<div class="box">
					<label class="input-label" for="url">父节点：</label>
					<div class="input-box w19">
						<input name="pid"  id="pid" type="hidden" info="请选择父节点" check="required"  />
						<input name="node_name" class="input" id="node_name" type="text"  readonly="readonly"/>
						<a class="add-on w6" onclick="select_pid()"> 选择 </a>
					</div>
				</div>
				<div class="box">
					<label class="input-label" for="icon">图标：</label>
					<input class="input w19" type="text" id="icon" name="icon" >
				</div>
				<div class="box">
					<label class="input-label" for="badge_function">统计函数：</label>
					<input class="input w19" type="text" id="badge_function" name="badge_function" >
				</div>
				<div class="box">
					<label class="input-label" for="sort">排序：</label>
					<input class="input w10" type="text" id="sort" name="sort" >
				</div>
				<div class="box">
					<label class="input-label" for="is_del">状态*：</label>
					<select  name="is_del" id="is_del" class="select w10">
						<option value="0">启用</option>
						<option value="1">禁用</option>
					</select>
					<i class="icon"></i>
				</div>
				<div class="box">
					<label class="input-label" for="remark" >备注：</label>
					<textarea class="textarea" id='remark' name="remark" rows="5" class="" ></textarea>
				</div>
			</form>
		</div>
	</div>
</block>
<block name="js">
	<script type="text/javascript">
		layui.use(['global'], function() {
			var fn = {
				add : function() {
					winopen("{:url('add')}", 560, 470);
				},
				save : function() {
					send_form('form_data', '{:url("save")}', '', function(ret) {
						if (ret.status == 1) {
							layer.msg(ret.info, {
								time : 1200
							}, function() {
								location.reload(true);
							});
						} else {
							layer.msg(ret.info);
							return false;
						}
					});
				},
				del : function() {
					if ($(".tree-menu a.active").length == 0) {
						layer.msg('请选择要删除的菜单');
						return false;
					}
					if ($(".tree-menu a.active + input").length > 0) {
						layer.msg('有子菜单不能删除');
						return false;
					}
					//信息框-例2
					layer.msg('确定要删除吗?', {
						time : 0,
						btn : ['确定', '取消'],
						yes : function(index) {
							var vars = $("#form_data").serialize();
							send_ajax("{:url('del')}", vars, function(ret) {
								if (ret.status) {
									layer.msg(ret.info, {
										time : 1200
									}, function() {
										location.reload(true);
									});
								}
							});
						},
						no : function(index) {
							layer.close(index);
						}
					});
				},
				select_pid : function() {
					winopen("{:url('select_pid')}", 560, 470);
				}
			};
			win_exp(fn);
			set_return_url(null);
			set_val('eq_pid', '{$eq_pid}');

			$(".tree-menu a").click(function() {
				$this = $(this);
				$(".tree-menu  a").removeClass('active');
				$this.addClass('active');
				vars = {};
				vars.id = $this.attr("node");
				send_ajax("{:url('read')}", vars, function(ret) {
					show_data(ret);
				});
				return false;
			});

			function show_data(result) {
				for (var s in result.data) {
					set_val(s, result.data[s]);
				};
				$("#node_name").val($("#node_list option[value='" + $("#pid").val() + "']").text());
				$("#opmode").val("edit");
			};

			$('#eq_pid').on('change', function() {
				$('#form_search').submit();
			});

		});

	</script>

</block>